<template>
  <div>
    <div id="playList-app" @click="closeMask">
      <!-- 头部展示 -->
      <div class="headImg" @click.stop="showMask">
        <div class="coverImg">
          <img :src="collectionDetail.coverImgUrl" alt />
        </div>
        <div class="info">
          <div class="van-ellipsis title" v-text="collectionDetail.title"></div>
          <div class="user">
            <img :src="collectionDetail.avatarUrl" alt />
            <div class="van-ellipsis" v-text="collectionDetail.user"></div>
          </div>
          <div class="van-ellipsis description" v-text="collectionDetail.description"></div>
        </div>
      </div>
      <!-- 展示列表 -->
      <div class="display">
        <van-cell-group>
          <van-cell
            @click="playMusic(item.id, item.name, item.singer,item.picId, item.lyric)"
            :title="item.name"
            :label="item.singer"
            v-for="item in collectionList" :key="item.id"
          >
            <template #right-icon>
              <van-icon name="play-circle-o" size="30" color="#eee " />
            </template>
          </van-cell>
        </van-cell-group>
      </div>
    </div>
    <div class="allmask">
      <!-- 遮罩 -->
      <div :style="backgroundStyle"></div>
      <div :style="backgroundStyle2"></div>
      <div class="fullMask"></div>
      <!-- 模态框 -->
      <transition mode="out-in">
        <div v-if="maskFlag" class="mask">
          <div class="background"></div>
          <div class="van-ellipsis title" v-text="collectionDetail.title"></div>
          <div class="coverImg">
            <img :src="collectionDetail.coverImgUrl" alt />
          </div>
          <div class="user">
            <img :src="collectionDetail.avatarUrl" alt />
            <div class="van-ellipsis" v-text="collectionDetail.user"></div>
          </div>
          <p class="description" v-text="collectionDetail.description"></p>
        </div>
      </transition>
    </div>
  </div>
</template>

<script>
//导入jquery
import $ from "jquery";
export default {
  data: function() {
    return {
      collectionList: [],
      //遮罩样式对象
      backgroundStyle: {
        background: "",
        position: "fixed",
        top: 0,
        left: "0",
        bottom: "65%",
        right: "0",
        zIndex: -1,
        filter: "blur(5px) brightness(50%)"
      },
      backgroundStyle2: {
        background: "",
        position: "fixed",
        top: 0,
        left: "0",
        bottom: "65%",
        right: "0",
        zIndex: -2,
        filter: "brightness(50%)"
      },
      //歌单详情
      collectionDetail: {
        coverImgUrl: "",
        title: "",
        user: "",
        avatarUrl: "",
        description: ""
      },
      //控制模态框的flag
      maskFlag: false
    };
  },
  // props: ["PlayingList"],
  beforeMount() {
    //获取请求路径上的id
    let id = this.$route.params.id;
    //根据id获取歌单
    this.$http.get("playlist/detail?id=" + id+"&cookie="+localStorage.getItem('cookie')).then(result => {
      //获取到所有的id，forEach处理
      result.data.playlist.trackIds.forEach((item, index) => {
        // 根据id获取详情
        this.$http.get("song/detail?ids=" + item.id).then(result => {
          // console.log(result.data.songs[0]);
          let detail = result.data.songs[0];
          this.collectionList.push({
            index: index,
            id: detail.id,
            name: detail.name,
            singer: detail.ar[0].name,
            url:
              "https://music.163.com/song/media/outer/url?id=" +
              detail.id +
              ".mp3",
            picId: detail.al.id
          });
        });
      });
      //获取歌单封面
      this.collectionDetail.coverImgUrl = result.data.playlist.coverImgUrl;
      //获取歌单标题
      this.collectionDetail.title = result.data.playlist.name;
      //获取歌单用户
      this.collectionDetail.user = result.data.playlist.creator.nickname;
      //获取歌单用户头像url
      this.collectionDetail.avatarUrl = result.data.playlist.creator.avatarUrl;
      //获取歌单简介
      this.collectionDetail.description = result.data.playlist.description;
      this.backgroundStyle.background =
        "url(" + this.collectionDetail.coverImgUrl + ")";
      this.backgroundStyle2.background =
        "url(" + this.collectionDetail.coverImgUrl + ")";
      // console.log(result.data);
    });
  },
  methods: {
    //点击音乐
    playMusic(id, SongName, SingerName, picId, lyric) {
      this.$emit(
        "clickCollection",
        id,
        SongName,
        SingerName,
        picId,
        lyric,
        this.collectionList
      );
    },
    // 展示模态框
    showMask() {
      if (this.maskFlag == true) {
        $("#playList-app").css({ filter: "blur(0)" });
        this.maskFlag = false;
      } else if (this.maskFlag == false) {
        $("#playList-app").css({ filter: "blur(20px)" });
        this.maskFlag = true;
      }
    },
    //关闭模态框
    closeMask() {
      if (this.maskFlag == true) {
        $("#playList-app").css({ filter: "blur(0)" });
        this.maskFlag = false;
      }
    }
  }
};
</script>

<style lang="scss">
#playList-app {
  overflow: hidden;
  .headImg {
    width: 100%;
    padding: 30%;
    display: flex;
    .coverImg {
      width: 40%;
      img {
        width: 100%;
        border-radius: 10px;
      }
    }
    .info {
      padding-top: 10px;
      padding-left: 20px;
      width: 60%;
      color: white;
      .title {
        font-size: 18px;
      }
      .user {
        margin-top: 15px;
        font-size: 14px;
        line-height: 1.5em;
        display: flex;
        img {
          height: 15%;
          width: 15%;
          border-radius: 20px;
          margin-right: 15px;
        }
      }
      .description {
        margin-top: 20px;
        font-size: 12px;
      }
    }
  }
  .display {
    background: white;
    border-radius: 20px 20px 0 0;
    padding-top: 20px;
  }
  //模糊遮罩
  // .fullMask {
  //   position: fixed;
  //   top: -20%;
  //   bottom: -20%;
  //   left: -20%;
  //   right: -20%;
  //   z-index: 1;
  //   background: rgba(255, 255, 255, 0.8);
  //   filter: blur(20px);
  // }
}
.allmask {
  //详情遮罩
  .mask {
    position: fixed;
    top: 25%;
    left: 10%;
    width: 80%;
    padding: 5%;
    border-radius: 20px;
    color: white;
    z-index: 10;
    .background {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      height: 100%;
      border-radius: 20px;
      z-index: -1;
      filter: brightness(0.8);
      background: url("../images/background/playListDetailBackground.png");
    }
    .coverImg {
      text-align: center;
      margin-top: 5%;
      img {
        width: 50%;
        border-radius: 20px;
        text-align: center;
      }
    }
    .title {
      width: 80%;
      margin: 0 auto;
      font-size: 15px;
      text-align: center;
    }
    .user {
      margin-top: 5%;
      font-size: 14px;
      line-height: 1.5em;
      display: flex;
      justify-content: center;
      img {
        height: 5%;
        width: 5%;
        margin-right: 5px;
        border-radius: 20px;
      }
    }
    .description {
      color: white;
      text-indent: 2em;
      margin: 0 auto;
      width: 80%;
      margin-top: 4%;
      font-size: 8px;
      word-wrap: break-word;
      text-align: center;
    }
  }
}

//动画
.v-enter,
v-leave-to {
  opacity: 0;
}
.v-enter-active,
v-leave-active {
  transition: all 0.4s ease;
}
</style>